function check_register()
{
	var username = $("#txt_username").val();
	
	var email = $("#txt_email").val();
	
	var password = $("#txt_password").val();
	
	var repassword = $("#txt_repassword").val();
	
	if (!username || username.length <= 5)
	{
		reload_key();
		$("#txt_username").focus();
		alert_msg('<span style="color:#C00">Username phải từ 5 ký tự trở lên</span> !');
		$("#txt_password").val("");
		$("#txt_repassword").val("");
		return false;
	}
	
	else if (!email.match(/^([-\d\w][-.\d\w]*)?[-\d\w]@([-\w\d]+\.)+[a-zA-Z]{2,6}$/))
	{
		reload_key();
		$("#txt_email").focus();
		alert_msg('<span style="color:#C00">Email không dúng</span> !');
		$("#txt_password").val("");
		$("#txt_repassword").val("");
		return false;
	}	
	else if (!password || password.length <= 5)
	{
		reload_key();
		$("#txt_password").focus();
		$("#txt_password").val("");
		$("#txt_repassword").val("");
		alert_msg('<span style="color:#C00">Password phải từ 5 ký tự trở lên</span> !');
		return false;
	}	
	else if (password != repassword)
	{
		reload_key();
		$("#txt_password").focus();
		$("#txt_password").val("");
		$("#txt_repassword").val("");
		alert_msg('<span style="color:#C00">Password chưa đúng</span> !');
		return false;
	}
	var query = $query(".frm_login")+"&act=register";
	$.ajaxIt(query,'/action.php',function(x)
	{
		x = $.trim(x);
		if (x.substring(0,2) == 'OK')
		{
			alert_msg(x.substring(3));
			var t = setTimeout(function()
			{
				window.location = "/login/banh-my-da-nang.html";
			},3000);
		}
		else if (x.substring(0,4) == "FAIL")
		{
			alert_msg(x.substring(5));
			reload_key();
		}
		else {
			reload_key();
			$("#txt_password").val("");
			$("#txt_repassword").val("");
			alert_msg(x);
		}
	});
	
	return false;
}

function reload_key()
{
	$.ajaxIt('act=reload_key','/action.php',function(x)
	{
		$("#txt_password").val("");
		$("#txt_repassword").val("");
		x= $.trim(x);
		$(".td_body").html(x);
	});
}

function check_login()
{
	var username = $("#txt_login_username").val();
	var password = $("#txt_login_password").val();
	if (username.length < 1)
	{
		alert_msg("Xin vui lòng nhập username");
		return false;
	}
	if (password.length < 1)
	{
		alert_msg("Xin vui lòng password");
		return false;
	}
	var query = $query('.frm_register') + "&act=login";
	
	$.ajaxIt(query,'/action.php',function(x)
	{
		x = $.trim(x);
		if (x.substring(0,2) == 'OK') {
			alert_msg(x.substring(3));
			var t = setTimeout(function()
			{
				window.location = "/";
			},2000);
		}
		else {
			alert_msg(x);
			$("#txt_login_password").val('');
		}
	});
	
	return false; 
}

function signout()
{
	$.ajaxIt('act=signout','/action.php',function(x)
	{
		alert_msg(x);
		var t = setTimeout(function()
		{
			window.location = "/";
		},3000);
	});
}